package com.zhs.gccs.view.taskMap;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.mapbox.geojson.Point;
import com.zhs.gccs.R;
import com.zhs.gccs.model.TaskProject;
import com.zhs.gccs.view.BaseView;
import com.zhs.gccs.utils.OnNoDoubleClickListener;

public class AddNavMarkerView extends BaseView {
    private TextView tv_project;
    private TextView tv_address;
    private EditText et_remarks;//
    private View btn_close;
    private View btn_save;

    public AddNavMarkerView(@NonNull Context context) {
        super(context);
    }

    public AddNavMarkerView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public AddNavMarkerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_map_marker_add_nav, this, true);
//        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomerLogo);
//        String title = typedArray.getString(R.styleable.CustomerInfoItem_preText);
//        typedArray.recycle();
        tv_project = view.findViewById(R.id.tv_project);
        tv_address = view.findViewById(R.id.tv_address);
        et_remarks = view.findViewById(R.id.et_remarks);
        btn_close = view.findViewById(R.id.btn_close);
        btn_save = view.findViewById(R.id.btn_save);
        btn_close.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (markerNavListener != null) markerNavListener.onCancel();
            }
        });
        btn_save.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (markerNavListener != null) markerNavListener.onSave();
            }
        });
    }

    public String getAddress() {
        return address;
    }

    private String address;

    public AddNavMarkerView setAddress(String address) {
        this.address = address;
        tv_address.setText(address);
        return this;
    }

    public String getRemarks(){
        return et_remarks.getText().toString();
    }

    public TaskProject getProject() {
        return taskProject;
    }

    private Point point;

    public Point getPoint() {
        return point;
    }

    public AddNavMarkerView setPoint(Point point) {
        this.point = point;
        return this;
    }

    private TaskProject taskProject;

    public AddNavMarkerView setProject(TaskProject taskProject) {
        this.taskProject = taskProject;
        if (taskProject != null && !TextUtils.isEmpty(taskProject.getpName())) {
            tv_project.setText(taskProject.getpName());
            tv_project.setVisibility(VISIBLE);
        } else {
            tv_project.setText("");
            tv_project.setVisibility(GONE);
        }
        return this;
    }

    public void setMarkerNavListener(MarkerNavListener markerNavListener) {
        this.markerNavListener = markerNavListener;
    }

    private MarkerNavListener markerNavListener;

    public interface MarkerNavListener {
        void onCancel();
        void onSave();
    }
}
